CREATE TABLE [dbo].[TTCNTA_DIST]
(
[CO_EMPR] [dbo].[TD_VC_002] NOT NULL,
[NU_ANNO] [dbo].[TD_IN_004_ANNO] NOT NULL CONSTRAINT [DF__TTCNTA_DI__NU_AN__15A53433] DEFAULT (datepart(year,getdate())),
[NU_MESE] [dbo].[TD_IN_002_MESE] NOT NULL,
[CO_CNTA_ORIG] [dbo].[TD_VC_020_CNTA] NOT NULL,
[CO_CNTA_DEST] [dbo].[TD_VC_020_CNTA] NOT NULL,
[PO_DIST] [dbo].[TD_NU_009_004] NOT NULL CONSTRAINT [DF__TTCNTA_DI__PO_DI__1A69E950] DEFAULT ((1.000)),
[CO_USUA_CREA] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_CREA] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TTCNTA_DI__FE_US__1C5231C2] DEFAULT (getdate()),
[CO_USUA_MODI] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_MODI] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TTCNTA_DI__FE_US__1D4655FB] DEFAULT (getdate())
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [CK__TTCNTA_DI__CO_CN__1881A0DE] CHECK (([CO_CNTA_ORIG]>='0' AND [CO_CNTA_ORIG]<='99999999999999999999'))
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [CK__TTCNTA_DI__CO_CN__1975C517] CHECK (([CO_CNTA_DEST]>='0' AND [CO_CNTA_DEST]<='99999999999999999999'))
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [CK__TTCNTA_DI__NU_AN__1699586C] CHECK (([NU_ANNO]>=(0)))
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [CK__TTCNTA_DI__NU_ME__178D7CA5] CHECK (([NU_MESE]>=(0) AND [NU_MESE]<=(13)))
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [CK__TTCNTA_DI__PO_DI__1B5E0D89] CHECK (([PO_DIST]>=(0)))
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [XPKTTCNTA_DIST] PRIMARY KEY CLUSTERED  ([CO_EMPR], [NU_ANNO], [NU_MESE], [CO_CNTA_ORIG], [CO_CNTA_DEST]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [TMPARA_CONT_A_TTCNTA_DIST] FOREIGN KEY ([CO_EMPR]) REFERENCES [dbo].[TMPARA_CONT] ([CO_EMPR])
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [TMPLAN_ANNO_A_TTCNTA_DIST_01] FOREIGN KEY ([CO_EMPR], [CO_CNTA_DEST]) REFERENCES [dbo].[TMPLAN_ANNO] ([CO_EMPR], [CO_CNTA_EMPR])
GO
ALTER TABLE [dbo].[TTCNTA_DIST] ADD CONSTRAINT [TMPLAN_ANNO_A_TTCNTA_DIST_02] FOREIGN KEY ([CO_EMPR], [CO_CNTA_ORIG]) REFERENCES [dbo].[TMPLAN_ANNO] ([CO_EMPR], [CO_CNTA_EMPR])
GO
